home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / modem / qfaxv105.zip / MANYFAX.C < prev    next >
C/C++ Source or Header  |  1996-06-16  |  5KB  |  130 lines

  1. /*************************************************************************/
  2. /*  MANYFAX.C     Send many faxes automatically by calling QFAX.EXE      */
  3. /*          Copyright (C) 1996 Anthony Mai. All rights reserved          */
  4. /*                                                                       */
  5. /*  You may modify and use this program for any purpose as long as this  */
  6. /*  copyright notice remains intact. But you may not re-distribute this  */
  7. /*  file except when you distribute it in it's original form, as part of */
  8. /*  the QFAXV105.ZIP shareware package.                                  */
  9. /*************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <process.h>
  14.  
  15. int i,j,k,Ans, returncode;
  16. char qfaxcmd[128]; tmpstr[128];
  17. char listname[64], logname[64];
  18. char filename[20], phone[20];
  19. char dirnam[128];
  20. FILE * fbase, * ftemp;
  21.  
  22. usage()
  23. {
  24.  printf("Usage of this program is:\n"
  25.         "  manyfax  -db fax_list_file -log log_file_name\n"
  26.         "Example:\n"
  27.         "  manyfax  -db manyfax.fdb  -log manyfax.log\n"
  28.         "Contact mai@phys.psu.edu if there is a problem.\n");
  29. }
  30.  
  31. main(argc, argv)
  32.   int argc;
  33.   char * argv[];
  34. {
  35.   _asm {
  36.     mov  ax, 03h
  37.     int  10h
  38.    }
  39.  
  40.   printf("\nThis program demonstrate how to call QFAX from other programs\n"
  41.          "and send out many faxes to different fax numbers\n\n");
  42.   printf("You can use the spawl function in C to invoke QFAX from your program\n");
  43.   printf("The file manyfax.fdb is a plain ASCII file that stores file names\n"
  44.          "and fax numbers like this format:\n\n");
  45.   printf("File#1      Fax_Number#1\n"
  46.          "File#2      Fax_Number#2\n"
  47.          "File#3      Fax_Number#3\n...\n\n");
  48.  
  49.  
  50.  /* Find the the name of the directory where manyfax.exe and qfax.exe is */
  51.  strcpy(dirnam, argv[0]);
  52.  i = strlen(dirnam)-1;
  53.  while (i>0 && (*(dirnam+i) != '\134')) i--;
  54.  *(dirnam+i+1) = '\0';
  55.  
  56.  if (argc == 1) {usage(); exit(-1);}
  57.   
  58.   /*  Construct the QFAX command with the path name */
  59.   strcpy(qfaxcmd, dirnam);
  60.   strcat(qfaxcmd, "\\");
  61.   strcat(qfaxcmd, "qfax.exe");
  62.  
  63.   /* Test whether the the QFAX path and file name is correct or not */
  64.   if ((ftemp = fopen(qfaxcmd, "rb")) == NULL) {
  65.       printf("%s can not be found!\n", qfaxcmd); exit(-1);
  66.      }
  67.   else fclose(ftemp);
  68.  
  69.   strcpy(listname, "manyfax.fdb");
  70.   strcpy(logname,  "manyfax.log");
  71.  
  72.   i = 1;
  73.   while (i<argc)
  74.    {
  75.     if (*(argv[i]) == '-') switch (*(argv[i]+1)) {
  76.       case 'd': i++; strcpy(listname, argv[i]); break;
  77.       case 'l': i++; strcpy(logname,  argv[i]); break;
  78.      }
  79.     i ++;
  80.    }
  81.  
  82.   if ((fbase = fopen(listname, "rb")) == NULL) {
  83.      printf("Database file %s not found\n", listname); exit(-1);
  84.     }
  85.   if ((ftemp = fopen(logname, "wb")) == NULL) {
  86.      printf("Can not create file %s\n", logname); exit(-1);
  87.     }
  88.  
  89.   while (!feof(fbase)) {
  90.     filename[0] = 0x00; phone[0] = 0x00;
  91.     fscanf(fbase, "%s", filename);
  92.     if (strlen(filename)) {
  93.        fscanf(fbase, "%s", phone);
  94.        if (strlen(phone)) {
  95.          printf("Trying to fax %s to %s using QFAX\n", filename, phone);
  96.          
  97.          /* Call QFAX as a command line faxer */
  98.  
  99.          returncode = spawnl(_P_WAIT, qfaxcmd, "qfax", "-nod",
  100.            filename, phone, NULL);
  101.  
  102.          /* The above is similar to DOS command line:                   */
  103.          /*    qfax -nod filename phone                                 */
  104.  
  105.          fprintf(ftemp, "%s -> %s  result: %d\n",filename,phone,returncode);
  106.  
  107.          printf("QFAX called. ");
  108.          switch(returncode) {
  109.             case  0: printf("FAX Successful.\n");               break;
  110.             case -1: printf("File, Memory or Modem errors.\n"); break;
  111.             case  1: printf("FAX partially completed.\n");      break;
  112.             case  2: printf("No FAX page transmitted.\n");      break;
  113.             case  3: printf("FAX handshake failed.\n");         break;
  114.             case  4: printf("Unknown error after dialing.\n");  break;
  115.             case  5: printf("Unable to Start FAX.\n");          break;
  116.             case  6: printf("Unable to reset or initialize modem.\n"); break;
  117.             case 10: printf("No Dial Tone on Phone Line.\n");   break;
  118.             case 11: printf("Phone Line Busy.\n");              break;
  119.             case 12: printf("Fax Connection Time Out.\n");      break;
  120.             default: printf("Unknown FAX error.\n");            break;
  121.           }
  122.         }
  123.       }
  124.    }
  125.  
  126.   fclose(ftemp);
  127.   fclose(fbase);
  128.   printf("All done. Read the file %s for a log of fax results\n", logname);
  129. }
  130.